const cos_map = {
  0: 1,
  1: 0.99984769,
  2: 0.99939082,
  3: 0.99862953,
  4: 0.99756405,
  5: 0.99619469,
  6: 0.99452189,
  7: 0.99254615,
  8: 0.99026806,
  9: 0.98768834,
  10: 0.98480775,
  11: 0.98162718,
  12: 0.9781476,
  13: 0.97437006,
  14: 0.97029572,
  15: 0.96592582,
  16: 0.96126169,
  17: 0.95630475,
  18: 0.95105651,
  19: 0.94551857,
  20: 0.93969262,
  21: 0.93358042,
  22: 0.92718385,
  23: 0.92050485,
  24: 0.91354545,
  25: 0.90630778,
  26: 0.89879404,
  27: 0.89100652,
  28: 0.88294759,
  29: 0.8746197,
  30: 0.8660254,
  31: 0.8571673,
  32: 0.84804809,
  33: 0.83867056,
  34: 0.82903757,
  35: 0.81915204,
  36: 0.80901699,
  37: 0.79863551,
  38: 0.78801075,
  39: 0.77714596,
  40: 0.76604444,
  41: 0.75470958,
  42: 0.74314482,
  43: 0.7313537,
  44: 0.7193398,
  45: 0.70710678,
  46: 0.69465837,
  47: 0.68199836,
  48: 0.6691306,
  49: 0.65605902,
  50: 0.6427876,
  51: 0.62932039,
  52: 0.61566147,
  53: 0.60181502,
  54: 0.58778525,
  55: 0.57357643,
  56: 0.5591929,
  57: 0.54463903,
  58: 0.52991926,
  59: 0.51503807,
  60: 0.5,
  61: 0.48480962,
  62: 0.46947156,
  63: 0.45399049,
  64: 0.43837114,
  65: 0.42261826,
  66: 0.40673664,
  67: 0.39073112,
  68: 0.37460659,
  69: 0.35836794,
  70: 0.34202014,
  71: 0.32556815,
  72: 0.30901699,
  73: 0.2923717,
  74: 0.27563735,
  75: 0.25881904,
  76: 0.24192189,
  77: 0.22495105,
  78: 0.20791169,
  79: 0.19080899,
  80: 0.17364817,
  81: 0.15643446,
  82: 0.1391731,
  83: 0.12186934,
  84: 0.10452846,
  85: 0.08715574,
  86: 0.06975647,
  87: 0.05233595,
  88: 0.03489949,
  89: 0.0174524,
  90: 0,
  91: -0.01745241,
  92: -0.0348995,
  93: -0.05233596,
  94: -0.06975648,
  95: -0.08715575,
  96: -0.10452847,
  97: -0.12186935,
  98: -0.13917311,
  99: -0.15643447,
  100: -0.17364818,
  101: -0.190809,
  102: -0.2079117,
  103: -0.22495106,
  104: -0.2419219,
  105: -0.25881905,
  106: -0.27563736,
  107: -0.29237171,
  108: -0.309017,
  109: -0.32556816,
  110: -0.34202015,
  111: -0.35836795,
  112: -0.3746066,
  113: -0.39073113,
  114: -0.40673665,
  115: -0.42261827,
  116: -0.43837115,
  117: -0.4539905,
  118: -0.46947157,
  119: -0.48480963,
  120: -0.5,
  121: -0.51503808,
  122: -0.52991927,
  123: -0.54463904,
  124: -0.55919291,
  125: -0.57357644,
  126: -0.58778526,
  127: -0.60181503,
  128: -0.61566148,
  129: -0.6293204,
  130: -0.64278761,
  131: -0.65605903,
  132: -0.66913061,
  133: -0.68199837,
  134: -0.69465838,
  135: -0.70710679,
  136: -0.71933981,
  137: -0.73135371,
  138: -0.74314483,
  139: -0.75470959,
  140: -0.76604445,
  141: -0.77714597,
  142: -0.78801076,
  143: -0.79863552,
  144: -0.809017,
  145: -0.81915205,
  146: -0.82903758,
  147: -0.83867057,
  148: -0.8480481,
  149: -0.85716731,
  150: -0.86602541,
  151: -0.87461971,
  152: -0.8829476,
  153: -0.89100653,
  154: -0.89879405,
  155: -0.90630779,
  156: -0.91354546,
  157: -0.92050486,
  158: -0.92718386,
  159: -0.93358043,
  160: -0.93969263,
  161: -0.94551858,
  162: -0.95105652,
  163: -0.95630476,
  164: -0.9612617,
  165: -0.96592583,
  166: -0.97029573,
  167: -0.97437007,
  168: -0.97814761,
  169: -0.98162719,
  170: -0.98480776,
  171: -0.98768835,
  172: -0.99026807,
  173: -0.99254616,
  174: -0.9945219,
  175: -0.9961947,
  176: -0.99756406,
  177: -0.99862954,
  178: -0.99939083,
  179: -0.9998477,
  180: -1,
  181: -0.9998477,
  182: -0.99939083,
  183: -0.99862954,
  184: -0.99756406,
  185: -0.9961947,
  186: -0.9945219,
  187: -0.99254616,
  188: -0.99026807,
  189: -0.98768835,
  190: -0.98480776,
  191: -0.98162719,
  192: -0.97814761,
  193: -0.97437007,
  194: -0.97029573,
  195: -0.96592583,
  196: -0.9612617,
  197: -0.95630476,
  198: -0.95105652,
  199: -0.94551858,
  200: -0.93969263,
  201: -0.93358043,
  202: -0.92718386,
  203: -0.92050486,
  204: -0.91354546,
  205: -0.90630779,
  206: -0.89879405,
  207: -0.89100653,
  208: -0.8829476,
  209: -0.87461971,
  210: -0.86602541,
  211: -0.85716731,
  212: -0.8480481,
  213: -0.83867057,
  214: -0.82903758,
  215: -0.81915205,
  216: -0.809017,
  217: -0.79863552,
  218: -0.78801076,
  219: -0.77714597,
  220: -0.76604445,
  221: -0.75470959,
  222: -0.74314483,
  223: -0.73135371,
  224: -0.71933981,
  225: -0.70710679,
  226: -0.69465838,
  227: -0.68199837,
  228: -0.66913061,
  229: -0.65605903,
  230: -0.64278761,
  231: -0.6293204,
  232: -0.61566148,
  233: -0.60181503,
  234: -0.58778526,
  235: -0.57357644,
  236: -0.55919291,
  237: -0.54463904,
  238: -0.52991927,
  239: -0.51503808,
  240: -0.50000001,
  241: -0.48480963,
  242: -0.46947157,
  243: -0.4539905,
  244: -0.43837115,
  245: -0.42261827,
  246: -0.40673665,
  247: -0.39073113,
  248: -0.3746066,
  249: -0.35836795,
  250: -0.34202015,
  251: -0.32556816,
  252: -0.309017,
  253: -0.29237171,
  254: -0.27563736,
  255: -0.25881905,
  256: -0.2419219,
  257: -0.22495106,
  258: -0.2079117,
  259: -0.190809,
  260: -0.17364818,
  261: -0.15643447,
  262: -0.13917311,
  263: -0.12186935,
  264: -0.10452847,
  265: -0.08715575,
  266: -0.06975648,
  267: -0.05233596,
  268: -0.0348995,
  269: -0.01745241,
  270: -1e-8,
  271: 0.0174524,
  272: 0.03489949,
  273: 0.05233595,
  274: 0.06975647,
  275: 0.08715574,
  276: 0.10452846,
  277: 0.12186934,
  278: 0.1391731,
  279: 0.15643446,
  280: 0.17364817,
  281: 0.19080899,
  282: 0.20791169,
  283: 0.22495105,
  284: 0.24192189,
  285: 0.25881904,
  286: 0.27563735,
  287: 0.2923717,
  288: 0.30901699,
  289: 0.32556815,
  290: 0.34202014,
  291: 0.35836794,
  292: 0.37460659,
  293: 0.39073112,
  294: 0.40673664,
  295: 0.42261826,
  296: 0.43837114,
  297: 0.45399049,
  298: 0.46947156,
  299: 0.48480962,
  300: 0.5,
  301: 0.51503807,
  302: 0.52991926,
  303: 0.54463903,
  304: 0.5591929,
  305: 0.57357643,
  306: 0.58778525,
  307: 0.60181502,
  308: 0.61566147,
  309: 0.62932039,
  310: 0.6427876,
  311: 0.65605902,
  312: 0.6691306,
  313: 0.68199836,
  314: 0.69465837,
  315: 0.70710678,
  316: 0.7193398,
  317: 0.7313537,
  318: 0.74314482,
  319: 0.75470958,
  320: 0.76604444,
  321: 0.77714596,
  322: 0.78801075,
  323: 0.79863551,
  324: 0.80901699,
  325: 0.81915204,
  326: 0.82903757,
  327: 0.83867056,
  328: 0.84804809,
  329: 0.8571673,
  330: 0.8660254,
  331: 0.8746197,
  332: 0.88294759,
  333: 0.89100652,
  334: 0.89879404,
  335: 0.90630778,
  336: 0.91354545,
  337: 0.92050485,
  338: 0.92718385,
  339: 0.93358042,
  340: 0.93969262,
  341: 0.94551857,
  342: 0.95105651,
  343: 0.95630475,
  344: 0.96126169,
  345: 0.96592582,
  346: 0.97029572,
  347: 0.97437006,
  348: 0.9781476,
  349: 0.98162718,
  350: 0.98480775,
  351: 0.98768834,
  352: 0.99026806,
  353: 0.99254615,
  354: 0.99452189,
  355: 0.99619469,
  356: 0.99756405,
  357: 0.99862953,
  358: 0.99939082,
  359: 0.99984769,
}

const sin_map = {
  0: 0,
  1: 0.0174524,
  2: 0.03489949,
  3: 0.05233595,
  4: 0.06975647,
  5: 0.08715574,
  6: 0.10452846,
  7: 0.12186934,
  8: 0.1391731,
  9: 0.15643446,
  10: 0.17364817,
  11: 0.19080899,
  12: 0.20791169,
  13: 0.22495105,
  14: 0.24192189,
  15: 0.25881904,
  16: 0.27563735,
  17: 0.2923717,
  18: 0.30901699,
  19: 0.32556815,
  20: 0.34202014,
  21: 0.35836794,
  22: 0.37460659,
  23: 0.39073112,
  24: 0.40673664,
  25: 0.42261826,
  26: 0.43837114,
  27: 0.45399049,
  28: 0.46947156,
  29: 0.48480962,
  30: 0.49999999,
  31: 0.51503807,
  32: 0.52991926,
  33: 0.54463903,
  34: 0.5591929,
  35: 0.57357643,
  36: 0.58778525,
  37: 0.60181502,
  38: 0.61566147,
  39: 0.62932039,
  40: 0.6427876,
  41: 0.65605902,
  42: 0.6691306,
  43: 0.68199836,
  44: 0.69465837,
  45: 0.70710678,
  46: 0.7193398,
  47: 0.7313537,
  48: 0.74314482,
  49: 0.75470958,
  50: 0.76604444,
  51: 0.77714596,
  52: 0.78801075,
  53: 0.79863551,
  54: 0.80901699,
  55: 0.81915204,
  56: 0.82903757,
  57: 0.83867056,
  58: 0.84804809,
  59: 0.8571673,
  60: 0.8660254,
  61: 0.8746197,
  62: 0.88294759,
  63: 0.89100652,
  64: 0.89879404,
  65: 0.90630778,
  66: 0.91354545,
  67: 0.92050485,
  68: 0.92718385,
  69: 0.93358042,
  70: 0.93969262,
  71: 0.94551857,
  72: 0.95105651,
  73: 0.95630475,
  74: 0.96126169,
  75: 0.96592582,
  76: 0.97029572,
  77: 0.97437006,
  78: 0.9781476,
  79: 0.98162718,
  80: 0.98480775,
  81: 0.98768834,
  82: 0.99026806,
  83: 0.99254615,
  84: 0.99452189,
  85: 0.99619469,
  86: 0.99756405,
  87: 0.99862953,
  88: 0.99939082,
  89: 0.99984769,
  90: 1,
  91: 0.99984769,
  92: 0.99939082,
  93: 0.99862953,
  94: 0.99756405,
  95: 0.99619469,
  96: 0.99452189,
  97: 0.99254615,
  98: 0.99026806,
  99: 0.98768834,
  100: 0.98480775,
  101: 0.98162718,
  102: 0.9781476,
  103: 0.97437006,
  104: 0.97029572,
  105: 0.96592582,
  106: 0.96126169,
  107: 0.95630475,
  108: 0.95105651,
  109: 0.94551857,
  110: 0.93969262,
  111: 0.93358042,
  112: 0.92718385,
  113: 0.92050485,
  114: 0.91354545,
  115: 0.90630778,
  116: 0.89879404,
  117: 0.89100652,
  118: 0.88294759,
  119: 0.8746197,
  120: 0.8660254,
  121: 0.8571673,
  122: 0.84804809,
  123: 0.83867056,
  124: 0.82903757,
  125: 0.81915204,
  126: 0.80901699,
  127: 0.79863551,
  128: 0.78801075,
  129: 0.77714596,
  130: 0.76604444,
  131: 0.75470958,
  132: 0.74314482,
  133: 0.7313537,
  134: 0.7193398,
  135: 0.70710678,
  136: 0.69465837,
  137: 0.68199836,
  138: 0.6691306,
  139: 0.65605902,
  140: 0.6427876,
  141: 0.62932039,
  142: 0.61566147,
  143: 0.60181502,
  144: 0.58778525,
  145: 0.57357643,
  146: 0.5591929,
  147: 0.54463903,
  148: 0.52991926,
  149: 0.51503807,
  150: 0.49999999,
  151: 0.48480962,
  152: 0.46947156,
  153: 0.45399049,
  154: 0.43837114,
  155: 0.42261826,
  156: 0.40673664,
  157: 0.39073112,
  158: 0.37460659,
  159: 0.35836794,
  160: 0.34202014,
  161: 0.32556815,
  162: 0.30901699,
  163: 0.2923717,
  164: 0.27563735,
  165: 0.25881904,
  166: 0.24192189,
  167: 0.22495105,
  168: 0.20791169,
  169: 0.19080899,
  170: 0.17364817,
  171: 0.15643446,
  172: 0.1391731,
  173: 0.12186934,
  174: 0.10452846,
  175: 0.08715574,
  176: 0.06975647,
  177: 0.05233595,
  178: 0.03489949,
  179: 0.0174524,
  180: 0,
  181: -0.01745241,
  182: -0.0348995,
  183: -0.05233596,
  184: -0.06975648,
  185: -0.08715575,
  186: -0.10452847,
  187: -0.12186935,
  188: -0.13917311,
  189: -0.15643447,
  190: -0.17364818,
  191: -0.190809,
  192: -0.2079117,
  193: -0.22495106,
  194: -0.2419219,
  195: -0.25881905,
  196: -0.27563736,
  197: -0.29237171,
  198: -0.309017,
  199: -0.32556816,
  200: -0.34202015,
  201: -0.35836795,
  202: -0.3746066,
  203: -0.39073113,
  204: -0.40673665,
  205: -0.42261827,
  206: -0.43837115,
  207: -0.4539905,
  208: -0.46947157,
  209: -0.48480963,
  210: -0.50000001,
  211: -0.51503808,
  212: -0.52991927,
  213: -0.54463904,
  214: -0.55919291,
  215: -0.57357644,
  216: -0.58778526,
  217: -0.60181503,
  218: -0.61566148,
  219: -0.6293204,
  220: -0.64278761,
  221: -0.65605903,
  222: -0.66913061,
  223: -0.68199837,
  224: -0.69465838,
  225: -0.70710679,
  226: -0.71933981,
  227: -0.73135371,
  228: -0.74314483,
  229: -0.75470959,
  230: -0.76604445,
  231: -0.77714597,
  232: -0.78801076,
  233: -0.79863552,
  234: -0.809017,
  235: -0.81915205,
  236: -0.82903758,
  237: -0.83867057,
  238: -0.8480481,
  239: -0.85716731,
  240: -0.86602541,
  241: -0.87461971,
  242: -0.8829476,
  243: -0.89100653,
  244: -0.89879405,
  245: -0.90630779,
  246: -0.91354546,
  247: -0.92050486,
  248: -0.92718386,
  249: -0.93358043,
  250: -0.93969263,
  251: -0.94551858,
  252: -0.95105652,
  253: -0.95630476,
  254: -0.9612617,
  255: -0.96592583,
  256: -0.97029573,
  257: -0.97437007,
  258: -0.97814761,
  259: -0.98162719,
  260: -0.98480776,
  261: -0.98768835,
  262: -0.99026807,
  263: -0.99254616,
  264: -0.9945219,
  265: -0.9961947,
  266: -0.99756406,
  267: -0.99862954,
  268: -0.99939083,
  269: -0.9998477,
  270: -1,
  271: -0.9998477,
  272: -0.99939083,
  273: -0.99862954,
  274: -0.99756406,
  275: -0.9961947,
  276: -0.9945219,
  277: -0.99254616,
  278: -0.99026807,
  279: -0.98768835,
  280: -0.98480776,
  281: -0.98162719,
  282: -0.97814761,
  283: -0.97437007,
  284: -0.97029573,
  285: -0.96592583,
  286: -0.9612617,
  287: -0.95630476,
  288: -0.95105652,
  289: -0.94551858,
  290: -0.93969263,
  291: -0.93358043,
  292: -0.92718386,
  293: -0.92050486,
  294: -0.91354546,
  295: -0.90630779,
  296: -0.89879405,
  297: -0.89100653,
  298: -0.8829476,
  299: -0.87461971,
  300: -0.86602541,
  301: -0.85716731,
  302: -0.8480481,
  303: -0.83867057,
  304: -0.82903758,
  305: -0.81915205,
  306: -0.809017,
  307: -0.79863552,
  308: -0.78801076,
  309: -0.77714597,
  310: -0.76604445,
  311: -0.75470959,
  312: -0.74314483,
  313: -0.73135371,
  314: -0.71933981,
  315: -0.70710679,
  316: -0.69465838,
  317: -0.68199837,
  318: -0.66913061,
  319: -0.65605903,
  320: -0.64278761,
  321: -0.6293204,
  322: -0.61566148,
  323: -0.60181503,
  324: -0.58778526,
  325: -0.57357644,
  326: -0.55919291,
  327: -0.54463904,
  328: -0.52991927,
  329: -0.51503808,
  330: -0.50000001,
  331: -0.48480963,
  332: -0.46947157,
  333: -0.4539905,
  334: -0.43837115,
  335: -0.42261827,
  336: -0.40673665,
  337: -0.39073113,
  338: -0.3746066,
  339: -0.35836795,
  340: -0.34202015,
  341: -0.32556816,
  342: -0.309017,
  343: -0.29237171,
  344: -0.27563736,
  345: -0.25881905,
  346: -0.2419219,
  347: -0.22495106,
  348: -0.2079117,
  349: -0.190809,
  350: -0.17364818,
  351: -0.15643447,
  352: -0.13917311,
  353: -0.12186935,
  354: -0.10452847,
  355: -0.08715575,
  356: -0.06975648,
  357: -0.05233596,
  358: -0.0348995,
  359: -0.01745241,
}

export class MathUtils {
  /**
   *
   * @param {number} angle
   * @returns {number}
   */
  public static sin(angle: number): number {
    angle = this.toInt(angle)
    return sin_map[angle]
  }

  /**
   *
   * @param {number} angle 角度
   */
  public static cos(angle: number): number {
    angle = this.toInt(angle)
    return cos_map[angle]
  }

  /**
   * 返回一个 [0, 360) 的角度值
   */
  public static toInt(angle: number) {
    angle = Math.floor(angle % 360)
    if (angle < 0) {
      angle += 360;
    }
    return angle
  }

  public static atan2(y: number, x: number) {
    const angle = Math.atan2(y, x);
    return this.toInt(angle)
  }

  public static PI = 3.14159265;
}